<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>姓名案例-watch属性</title>
    <script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
<!--准备一个容器-->
<div id="root">
    姓：<input type="text" v-model="firstName"><br>
    名：<input type="text" v-model="lastName"><br>
    姓名：<span>{{fullName}}</span><br>
</div>
</body>
<script type="text/javascript">
    Vue.config.productionTip=false
    const vm =new Vue({
        el:"#root",
        data:{
            firstName:"张",
            lastName:"三",
            fullName:'张三'
        },
        watch:{
            firstName(val){
                setTimeout(()=>{
                    this.fullName=val+'-'+this.lastName
                },1000);
            },
            lastName(Val){
                this.fullName=this.firstName+'-'+Val
            }
       }
    })
</script>
</html>